<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>websocket测试</title>
    <style type="text/css">
        h3, h4 {
            text-align: center;
        }
    </style>
</head>
<body>

<h3>WebSocket测试，在<span style="color:red">控制台</span>查看测试信息输出！</h3>
<h4>
    [url=/api/ws/sendOne?message=单发消息内容&id=none]单发消息链接[/url]
    [url=/api/ws/sendAll?message=群发消息内容]群发消息链接[/url]
</h4>

<div id="message"></div>


<script type="text/javascript">
    var socket;
    if (typeof (WebSocket) == "undefined") {
        console.log("遗憾：您的浏览器不支持WebSocket");
    } else {
        console.log("恭喜：您的浏览器支持WebSocket");

        //实现化WebSocket对象
        //指定要连接的服务器地址与端口建立连接
        //注意ws、wss使用不同的端口。我使用自签名的证书测试，
        //无法使用wss，浏览器打开WebSocket时报错
        //ws对应http、wss对应https。
        socket = new WebSocket("ws://localhost:8080/ws/asset/tony");
        //连接打开事件
        socket.onopen = function () {
            console.log("Socket 已打开");
            socket.send("发送消息到服务端(From Client)");
            socket.send
        };
        //收到消息事件
        socket.onmessage = function (msg) {
            console.log(msg.data);
            setMessageInnerHTML(msg.data);
        };
        //连接关闭回调方法
        socket.onclose = function () {
            setMessageInnerHTML("close");
            console.log("Socket已关闭");
        };
        //发生了错误事件
        socket.onerror = function () {
            alert("Socket发生了错误");
        }

        //窗口关闭时，关闭连接
        window.onbeforeunload = function () {
            socket.close();
        };

        //将消息显示在网页上
        function setMessageInnerHTML(innerHTML) {
            document.getElementById('message').innerHTML += innerHTML + '<br/>';
        }

    }
</script>

</body>
</html>


-Xms128m
-Xmx1024m
-XX:ReservedCodeCacheSize=512m
-XX:+UseConcMarkSweepGC
-XX:SoftRefLRUPolicyMSPerMB=50
-XX:CICompilerCount=2
-XX:+HeapDumpOnOutOfMemoryError
-XX:-OmitStackTraceInFastThrow
-verbose:gc
-XX:+PrintGCDetails
-XX:+PrintGCDateStamps
-ea
-Dsun.io.useCanonCaches=false
-Djdk.http.auth.tunneling.disabledSchemes=""
-Djdk.attach.allowAttachSelf=true
-Djdk.module.illegalAccess.silent=true
-Dkotlinx.coroutines.debug=off

-XX:ErrorFile=$USER_HOME/java_error_in_idea_%p.log
-XX:HeapDumpPath=$USER_HOME/java_error_in_idea.hprof
-javaagent:/Users/xiatian/.BetterIntelliJ/BetterIntelliJ-1.16.jar